﻿using System.Windows.Controls;
using System.Windows.Media;
using Infragistics.Controls.Charts;
using StartupSolution.Models;

namespace StartupSolution.Views.Treemaps
{
    /// <summary>
    /// Interaction logic for CustomValueMapper.xaml
    /// </summary>
    public partial class CustomValueMapper : Page
    {
        public CustomValueMapper()
        {
            InitializeComponent();
        }
    }

    #region Custom Mapper
    public class QuantityMapper : ValueMapper
    {
        private Brush _alertBrush = new SolidColorBrush(Colors.Red);

        //This method is called for every node of the mapped nodes.
        //TODO: Modify the custom logic according to your scenario.
        public override void MapValue(TreemapNode node)
        {
            if (node.DataContext == null)
            {
                return;
            }

            //Check if the current node is of the ValueTypeName.
            if (this.ValueTypeName == node.DataContext.GetType().Name)
            {
                InventoryEntry inventoryEntry = (InventoryEntry)node.DataContext;

                //The custom logic
                if (inventoryEntry.Quantity < 300)
                {
                    node.Fill = _alertBrush;
                }
            }
        }

        public override void ResetValue(TreemapNode node)
        {

        }
    }
    #endregion
}

